import { request } from "../../request/index.js"
//这里使用ES7 的async await 需要这个,不能app.js全局使用,必须单独使用
//https://github.com/yangsuai/regeneratorRuntime
import regeneratorRuntime from '../../lib/runtime/runtime.js';
import { getSetting, chooseAddress, openSetting, showModal, showToast } from "../../utils/asyncWx.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo:{},
    //被收藏的商品数量
    collectNums:0
  },


  onShow: function () {
    const userinfo = wx.getStorageSync("userinfo");
    const collect = wx.getStorageSync("collect")||[];

    this.setData({ userinfo, collectNums: collect.length});
  },
  //点击收货地址
  async handleChooseAddressManager(e) {
    try {
      //获取收货地址
      const res1 = await getSetting();
      //2 获取权限状态 主要发现一些 属性名很怪异的时候 都要使用[]形式来获取属性值
      const scopeAddress = res1.authSetting["scope.address"];
      //判断权限状态
      // if (scopeAddress === true || scopeAddress === undefined) {
      if (scopeAddress === false) {
        //用户以前拒绝过授予权限  先诱导用户打开授权页面
        await openSetting();
      }
      //调用获取收货地址的api
      const address = await chooseAddress();
      address.all = address.provinceName + address.cityName + address.countyName + address.detailInfo;

      //存入到缓存中
      wx.setStorageSync("address", address);

    } catch (error) {
      console.log(error)
    }

  }

  
})